package gui.messageview;

import java.awt.Color;
import java.awt.Component;



import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.DefaultListCellRenderer;

import no.ntnu.fp.model.Message;

import query.MessageQuery;

public class MessageListRenderer implements ListCellRenderer{
	private DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();

	@Override
	public Component getListCellRendererComponent(JList list, Object message,
			int index, boolean isSelected, boolean callHasFocus) {

		
		JLabel rend = (JLabel) defaultRenderer.getListCellRendererComponent(list, message, index, isSelected, callHasFocus);	
		Message msg = (Message) message;
		int check = MessageQuery.isAnswered(msg.getTo().getId(), msg.getMoteID());
		if(check==1){
			rend.setIcon(new ImageIcon(getClass().getResource("resources//email_open.png")));
			rend.setForeground(Color.GREEN);
		}
		else if(check == 0){
			rend.setForeground(Color.RED);
			rend.setIcon(new ImageIcon(getClass().getResource("resources//email_open.png")));
		}
		else{
			rend.setIcon(new ImageIcon(getClass().getResource("resources//email.png")));
		}
		
		return rend;
	}

}
